Conditions | 5 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 5 |
Changes | 0 |
1 | import toJson from './toJson.js'; |
||
3 | export default function intersect(original, array, multi) { |
||
4 | 4 | const jsonValue = toJson(array); |
|
5 | 4 | const arrayLength = array.length; |
|
6 | |||
7 | 4 | return original.filter((value) => { |
|
8 | 12 | const valueToJson = JSON.stringify(value); |
|
9 | 12 | if (multi) { |
|
10 | 6 | const found = jsonValue.reduce((accumulator, currentValue) => { |
|
11 | 12 | if (currentValue.includes(valueToJson)) { |
|
12 | 8 | return accumulator + 1; |
|
13 | } |
||
14 | |||
15 | 4 | return accumulator; |
|
16 | }, 0); |
||
17 | |||
18 | 6 | return found === arrayLength; |
|
19 | } |
||
20 | |||
21 | 6 | return jsonValue.includes(valueToJson); |
|
22 | }); |
||
23 | } |
||
24 |